package demo;
//定义抽象类
abstract class Shape {
    public abstract double area();
}
class Triangle extends Shape {
    private double a, b, c;
    public Triangle(double a, double b, double c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }
    public double area() {
        double p = (a + b + c) / 2;
        return Math.sqrt(p * (p - a) * (p - b) * (p - c));
    }
}
class Rectangle extends Shape {
    private double width, height ;
    public Rectangle(double width, double height) {
        this.width = width;
        this.height = height;
    }
    public double area() {
        return width * height;
    }
}
class demo03 {
    public static void main(String[] args) {
        //抽象类不能创建实例，但是可以定义引用变量指向子类对象
        Shape[] shapes = new Shape[2];
        shapes[0] = new Triangle(25, 41, 50);
        shapes[1] = new Rectangle(2, 3);
        for (Shape shape : shapes) {
            System.out.println(shape.area());
        }
    }
}